package client.commands;

import java.io.FileInputStream;
import java.io.IOException;
import java.io.ObjectInputStream;

import client.Player;
import client.StateContext;
import client.World;
import client.states.ExploreScreen;

public class LoadGameCommand implements ICommand {

	public LoadGameCommand() {

	}

	@Override
	public void execute(StateContext state) {
		String filename = "savedGame.txt";
		Player player = null;
		FileInputStream fis = null;
		ObjectInputStream in = null;

		try {
			fis = new FileInputStream(filename);
			in = new ObjectInputStream(fis);
			player = (Player) in.readObject();
			in.close();
			//start game
			World world = new World();
			ExploreScreen explore = new ExploreScreen(player, world);
			state.setState(explore);
		} catch (IOException ex) {
			ex.printStackTrace();
			//display error
		} catch (ClassNotFoundException ex) {
			ex.printStackTrace();
		} 
		
	}

	public String toString() {
		return "Load Game";
	}

}
